home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / flying-6.11 / objtab.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-30  |  2.1 KB  |  81 lines

  1. #ifndef _objtab_h
  2. #define _objtab_h
  3.  
  4. #ifndef _real_h
  5. #    include "real.h"
  6. #endif
  7. #ifndef _object_h
  8. #    include "object.h"
  9. #endif
  10.  
  11. #define DIRECT_ACCESS     1
  12.  
  13.  
  14. class ObjTab {
  15. public:
  16.     ObjTab()    : size(0) { };
  17.     ~ObjTab();
  18.  
  19.     void Init(int size);
  20.     int GetSize()                { return size; }
  21.  
  22.     Object *&operator[](unsigned i);
  23.  
  24.     Real &GetTime(unsigned i) const;
  25.     void SetTime(unsigned i, const Real &time_val);
  26.     void SetTimeDirect(unsigned i, const Real &time_val);
  27.  
  28.     void StartRecalc();
  29.     void ToFront( int i );
  30.     void ToBack( int i );
  31.     void StopRecalc();
  32.  
  33. private:
  34.     int        size;                // Gr÷▀e der Felder
  35.     Object    **obj;            // Feld mit den Objektzeigern
  36.     Real        *time;            // Feld mit den dazu geh÷renden Zeiten
  37.  
  38. #if (!DIRECT_ACCESS)
  39.     unsigned    *ind;                // Indexfeld bei normalen Zugriffen
  40.     unsigned    *new_ind;        // Feld zu Erstellung der neuen Index-Liste
  41.     unsigned    front, back;    // Indizes innerhalb der Index-Liste
  42. #endif
  43. };
  44.  
  45. #if (DIRECT_ACCESS)
  46. inline Object *&ObjTab::operator[](unsigned i)  {    return obj[i];    }
  47.  
  48. inline Real &ObjTab::GetTime(unsigned i) const
  49.                                             {    return time[i];    }
  50. inline void ObjTab::SetTime(unsigned i, const Real &time_val)
  51.                                             {    time[i] = time_val; }
  52. inline void ObjTab::SetTimeDirect(unsigned i, const Real &time_val)
  53.                                             {    time[i] = time_val; }
  54.  
  55. inline void ObjTab::StartRecalc()        { }
  56. inline void ObjTab::ToFront( int )        { }
  57. inline void ObjTab::ToBack( int )        { }
  58. inline void ObjTab::StopRecalc()            { }
  59. #else
  60. inline Object *&ObjTab::operator[](unsigned i)
  61.                                             {    return obj[ind[i]];    }
  62.  
  63. inline Real &ObjTab::GetTime(unsigned i) const
  64.                                             {    return time[ind[i]];    }
  65. inline void ObjTab::SetTime(unsigned i, const Real &time_val)
  66.                                             {    time[ind[i]] = time_val; }
  67. inline void ObjTab::SetTimeDirect(unsigned i, const Real &time_val)
  68.                                             {    time[i] = time_val; }
  69.  
  70. inline void ObjTab::StartRecalc()        { front=size; back=0; }
  71. inline void ObjTab::ToFront( int i )    { new_ind[--front]=ind[i]; }
  72. inline void ObjTab::ToBack( int i )        { new_ind[back++]=ind[i]; }
  73. inline void ObjTab::StopRecalc() {
  74.         memcpy( &ind[0], &new_ind[front], (size-front)*sizeof(unsigned) );
  75.         memcpy( &ind[size-front], &new_ind[0],  back*sizeof(unsigned) );
  76. }
  77. #endif
  78.  
  79.  
  80. #endif
  81.